package com.elysia.visionmanagerspringboot.controller;

import com.elysia.visionmanagerspringboot.domain.dto.AddResolutionDTO;
import com.elysia.visionmanagerspringboot.domain.dto.VideoDTO;
import com.elysia.visionmanagerspringboot.result.Result;
import com.elysia.visionmanagerspringboot.service.impl.IVideoServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/video")
@RequiredArgsConstructor
@Slf4j
public class VideoController {
    private final IVideoServiceImpl videoService;
    // 上传视频
    @PostMapping("/upload")
    public Result<Object> upload(@ModelAttribute VideoDTO videoDTO) throws Exception {
        log.info("上传视频{}", videoDTO);
        return videoService.update(videoDTO);
    }
    // 新增视频分辨率
    @PostMapping("/addResolution/{id}")
    public Result<Object> addResolution(@PathVariable Long id, @RequestBody AddResolutionDTO addResolutionDTO) throws Exception {
        log.info("新增视频{}的分辨率{}", id, addResolutionDTO.getResolutions());
        return videoService.addResolution(id, addResolutionDTO);
    }
    // 获取视频列表
    @GetMapping("/list")
    public Result<Object> list() {
        return videoService.getList();
    }
    // 删除视频
    @DeleteMapping("/{id}")
    public Result<Object> delete(@PathVariable Long id) {
        log.info("删除视频{}", id);
        return videoService.delete(id);
    }
    // 删除视频指定分辨率
    @DeleteMapping("/{id}/resolution/{resolution}")
    public Result<Object> delete(@PathVariable Long id, @PathVariable String resolution) {
        log.info("删除视频{}的{}分辨率", id, resolution);
        return videoService.delete(id, resolution);
    }
}
